package com.example.ignite;

import org.apache.ignite.Ignite;
import org.apache.ignite.IgniteCache;
import org.apache.ignite.Ignition;
import org.apache.ignite.cache.CacheAtomicityMode;
import org.apache.ignite.cache.CacheMode;
import org.apache.ignite.cache.CacheWriteSynchronizationMode;
import org.apache.ignite.configuration.CacheConfiguration;
import org.apache.ignite.configuration.IgniteConfiguration;
import org.apache.ignite.spi.communication.tcp.TcpCommunicationSpi;
import org.apache.ignite.spi.discovery.tcp.TcpDiscoverySpi;
import org.apache.ignite.spi.discovery.tcp.ipfinder.vm.TcpDiscoveryVmIpFinder;

import java.util.Arrays;

public class IgniteCluster2 
{
    public static void main(String[] args) throws InterruptedException {
        IgniteConfiguration igniteConfiguration = new IgniteConfiguration();
        igniteConfiguration.setClientMode(true);
        igniteConfiguration.setPeerClassLoadingEnabled(true);
        String cacheName = "myCache";
        CacheConfiguration cacheConfiguration = new CacheConfiguration(cacheName);
        cacheConfiguration.setCacheMode(CacheMode.PARTITIONED);
        cacheConfiguration.setBackups(2);
        cacheConfiguration.setWriteSynchronizationMode(CacheWriteSynchronizationMode.PRIMARY_SYNC);
        cacheConfiguration.setAtomicityMode(CacheAtomicityMode.TRANSACTIONAL);
        igniteConfiguration.setCacheConfiguration(cacheConfiguration);
        Ignite ignite = Ignition.start();

        IgniteCache<Integer, String> cache = ignite.getOrCreateCache(cacheName);
        System.out.println(System.currentTimeMillis() + " IgniteCluster2 start OK.");
        for(int i=31;i<60;i++) {
            System.out.println(System.currentTimeMillis() + " " + cache.get(i));
//            Thread.sleep(2000);
        }
    }
}